package com.hh.servlet.schedule;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hh.dao.ScheduleDAO;

/**
 * Servlet implementation class Schedule
 */
@WebServlet("/Schedule")
public class Schedule extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Schedule() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		response.setHeader("content-type", "text/html;charset=UTF-8");
		String zxks = request.getParameter("zxks");
		ScheduleDAO dao = new ScheduleDAO();
		JSONArray array = dao.getDoctorList(zxks);
		for(int i=0;i<array.size();i++){
			JSONObject obj = array.getJSONObject(i);
			for(int j=1;j<=24;j++){
				switch(j){
				case 1:
					obj.put("t"+j, dao.getPatient(zxks, "8:00", "8:30", obj.getString("zxry")));
					break;
				case 2:
					obj.put("t"+j, dao.getPatient(zxks, "8:30", "9:00", obj.getString("zxry")));
					break;
				case 3:
					obj.put("t"+j, dao.getPatient(zxks, "9:00", "9:30", obj.getString("zxry")));
					break;
				case 4:
					obj.put("t"+j, dao.getPatient(zxks, "9:30", "10:00", obj.getString("zxry")));
					break;
				case 5:
					obj.put("t"+j, dao.getPatient(zxks, "10:00", "10:30", obj.getString("zxry")));
					break;
				case 6:
					obj.put("t"+j, dao.getPatient(zxks, "10:30", "11:00", obj.getString("zxry")));
					break;
				case 7:
					obj.put("t"+j, dao.getPatient(zxks, "11:00", "11:30", obj.getString("zxry")));
					break;
				case 8:
					obj.put("t"+j, dao.getPatient(zxks, "11:30", "12:00", obj.getString("zxry")));
					break;
				case 9:
					obj.put("t"+j, dao.getPatient(zxks, "12:00", "12:30", obj.getString("zxry")));
					break;
				case 10:
					obj.put("t"+j, dao.getPatient(zxks, "12:30", "13:00", obj.getString("zxry")));
					break;	
				case 11:
					obj.put("t"+j, dao.getPatient(zxks, "13:00", "13:30", obj.getString("zxry")));
					break;
				case 12:
					obj.put("t"+j, dao.getPatient(zxks, "13:30", "14:00", obj.getString("zxry")));
					break;	
				case 13:
					obj.put("t"+j, dao.getPatient(zxks, "14:00", "14:30", obj.getString("zxry")));
					break;
				case 14:
					obj.put("t"+j, dao.getPatient(zxks, "14:30", "15:00", obj.getString("zxry")));
					break;	
				case 15:
					obj.put("t"+j, dao.getPatient(zxks, "15:00", "15:30", obj.getString("zxry")));
					break;
				case 16:
					obj.put("t"+j, dao.getPatient(zxks, "15:30", "16:00", obj.getString("zxry")));
					break;	
				case 17:
					obj.put("t"+j, dao.getPatient(zxks, "16:00", "16:30", obj.getString("zxry")));
					break;
				case 18:
					obj.put("t"+j, dao.getPatient(zxks, "16:30", "17:00", obj.getString("zxry")));
					break;	
				case 19:
					obj.put("t"+j, dao.getPatient(zxks, "17:00", "17:30", obj.getString("zxry")));
					break;
				case 20:
					obj.put("t"+j, dao.getPatient(zxks, "17:30", "18:00", obj.getString("zxry")));
					break;	
				case 21:
					obj.put("t"+j, dao.getPatient(zxks, "18:00", "18:30", obj.getString("zxry")));
					break;
				case 22:
					obj.put("t"+j, dao.getPatient(zxks, "18:30", "19:00", obj.getString("zxry")));
					break;	
				case 23:
					obj.put("t"+j, dao.getPatient(zxks, "19:00", "19:30", obj.getString("zxry")));
					break;
				case 24:
					obj.put("t"+j, dao.getPatient(zxks, "19:30", "20:00", obj.getString("zxry")));
					break;	
				}
			}
		}
		response.getWriter().print(array);
	}

}
